package com.oocl.ita.sakura.parser;

import com.oocl.ita.sakura.handler.ChatHandler;
import com.oocl.ita.sakura.handler.IHandler;
import com.oocl.ita.sakura.handler.InvalidHandler;
import com.oocl.ita.sakura.handler.LoginHandler;
import com.oocl.ita.sakura.handler.LogoutHandler;
import com.oocl.ita.sakura.handler.ShakeHandler;
import com.oocl.ita.sakura.protocol.Protocol;

public class ProtocolParser implements IParser {
	public IHandler parse(Protocol protocol) {
		System.out.println("ProtocolParse : " + Thread.currentThread().getName() + protocol);
		String msgType = protocol.getMsgType();

		IHandler handler = null;
		switch (msgType.toLowerCase()) {
		case "login":
			System.out.println("Parser : " + Thread.currentThread().getName() + " login");
			handler = new LoginHandler();
			break;
		case "logout":
			System.out.println("Parser : " + Thread.currentThread().getName() + " logout");
			handler = new LogoutHandler();
			break;
		case "chat":
		case "shake":
			System.out.println("Parser : " + Thread.currentThread().getName() + " chat");
			handler = new ChatHandler();
			break;
		default:
			System.out.println("Parser : " + Thread.currentThread().getName() + " Invalid MsgType");
			handler = new InvalidHandler();
			break;
		}

		return handler;
	}

}
